//index.js
//获取应用实例
const app = getApp()

//Page Object
import {request} from '../../request/index.js';
import regeneratorRuntime from '../../lib/runtime/runtime';
Page({
  data: {
    // 轮播图数据
    swiperList:'',
    // 导航数组
    catesList:'',
    // 楼层数据
    floorList:''
  },
  // 页面加载触发
  onLoad: function(options) {
    // 1.发送异步请求获取轮播图数据  优化的手段可以通过es6的promise来解决这个问题
    this.getSwiperList();
    this.getCateList();
    this.getFloorList();
  },
  // 获取轮播图数据
  async getSwiperList(){
    const result = await request({
      url: '/home/swiperdata',
      method: 'GET'
    })
      // .then(result => {
      //   this.setData({
      //     swiperList: result.data.message
      //   })
      // })
    this.setData({
          swiperList: result
        })

  },
  // 获取分类导航数据
  async getCateList() {
    const result = await request({
      url: '/home/catitems',
      method: 'GET'
    })
      // .then(result => {
      //   this.setData({
      //     catesList: result.data.message
      //   })
      // })
    this.setData({
          catesList: result
        })
    
  },
  // 获取楼层数据
  async getFloorList() {
    const result = await request({
      url: '/home/floordata',
      method: 'GET'
    })
      // .then(result => {
      //   this.setData({
      //     floorList: result.data.message
      //   })
      // })

    this.setData({
      floorList: result
    })

  },
  onReady: function() {
    
  },
  onShow: function() {
    
  },
  onHide: function() {

  },
  onUnload: function() {

  },
  onPullDownRefresh: function() {

  },
  onReachBottom: function() {

  },
  onShareAppMessage: function() {

  },
  onPageScroll: function() {

  },
  onTabItemTap:function(item) {

  }
});